package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbBrandExample;
import com.dongdongshop.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class BrandServiceImpl implements BrandService {

    private static final Logger logger = LoggerFactory.getLogger(BrandServiceImpl.class);

    @Resource
    private TbBrandMapper tbBrandMapper;

    @Override
    public PageInfo<TbBrand> listBrands(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> brands = tbBrandMapper.selectByExample(new TbBrandExample());
        PageInfo<TbBrand> pageInfo = new PageInfo<>(brands);
        logger.info("执行成功");
        return pageInfo;
    }

    @Override
    public int insertBrand(TbBrand tbBrand) {
        return tbBrandMapper.insertSelective(tbBrand);
    }

    @Override
    public TbBrand selectBrandById(Long id) {
        return tbBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateBrand(TbBrand tbBrand) {
        return tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    @Override
    public int deleteBrandBatch(Long[] ids) {
        return tbBrandMapper.deleteBrandBatch(ids);
    }

    @Override
    public List<TbBrand> getBrands() {
        return tbBrandMapper.selectByExample(new TbBrandExample());
    }
}
